﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using Model;
using BLL;

namespace LandAppraisal.Controllers
{
    /// <summary>
    /// 审核控制器
    /// </summary>
    public class ExamineController : ApiController
    {
        AdminBLL adminbll = new AdminBLL();
        EmployeeBLL empbll = new EmployeeBLL();

        #region 审核通过或者不通过
        /// <summary>
        ///  审核通过或者不通过
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public int ExamineUpdate(EAAuditing auditing)
        {
            auditing.Auditing_Time = DateTime.Now;
            auditing.Auditing_People = "admin";
            if (auditing.Auditing_Opinion == null)
            {
                auditing.Auditing_Opinion = "";
            }
            else
            {
                auditing.Auditing_Opinion = auditing.Auditing_Opinion;
            }
            if (empbll.Add<EAAuditing>(auditing) > 0)
            {
                if (empbll.ExamineUpdate(auditing.Auditing_Type, auditing.ProjectNumber) > 0)
                {
                    return 2; //添加并修改状态成功
                }
                else
                {
                    empbll.ExamineDelete(auditing.ProjectNumber);
                    return 3;//添加成功，修改不成功
                }
            }
            else
            {
                return 1;//未添加成功
            }
        }
        #endregion

        #region 根据项目编号查询项目详情
        /// <summary>
        /// 根据项目编号查询审核详情
        /// </summary>
        /// <param name="ProjectNumber"></param>
        /// <returns></returns>
        public string GetAuditDetails(string ProjectNumber)
        {
            return JsonConvert.SerializeObject(adminbll.GetAuditDetails(ProjectNumber));
        }
        #endregion
    }
}
